package cn.thoughtworks.school;

import cn.thoughtworks.school.services.TaskDiffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/diff")
public class TaskDiffController {
    @Autowired
    private TaskDiffService taskDiffService;

    @PostMapping("tasks")
    public ResponseEntity updateTaskNotification(@RequestBody Map data) {
        taskDiffService.updateTaskNotification(data);
        return new ResponseEntity(HttpStatus.CREATED);
    }

    @PostMapping("tasks/movement")
    public ResponseEntity moveTasksNotification(@RequestBody List<Map> datas) {
        taskDiffService.moveTaskNotification(datas);
        return new ResponseEntity(HttpStatus.CREATED);
    }

    @GetMapping("tasks/{taskId}/history")
    public ResponseEntity getTaskHistory(@PathVariable Long taskId) {
        return ResponseEntity.ok(taskDiffService.getTaskHistory(taskId));
    }
}
